import tool from '@/utils/tool';
import $ from 'jquery';

export default {
    clearlocalcache() {
        this.common_data = [];
        this.rmrptitem = '';
        this.rmrptunititem = [];
        this.rmInstrItem = '';
        this.rmallrptitem = '';
        this.rminputmdlrptitem = '';
        this.localrmcomddl = [];
        this.medresultList = [];
    },
    common_data: [],
    common_dataMulti: [],
    //药敏结果列表
    medresultList: [],
    async getMedResultList() {
        if (this.medresultList && this.medresultList.length > 0) {
            return this.medresultList;
        } else {
            const res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "medresultoption",
                }
            })
            this.medresultList = res.data;
            return res.data;
        }
    },
    //非细菌类的项目
    rmrptitem: '',
    async getrmrptitem() {
        if (this.rmrptitem && this.rmrptitem != "") {
            return this.rmrptitem;
        } else {
            let cData = await this.getallrptitem();
            try {
                cData = cData.filter(item => item.germflagid == "0");
                this.rmrptitem = cData;
            } catch (e) {
                this.rmrptitem = '';
            }
        }
        return this.rmrptitem;
    },
    //报告单元对应报告项目
    rmrptunititem: [],
    async getrptunititem(rptunitid) {
        let ritem = this.rmrptunititem.find(m => m.k == rptunitid);
        if (ritem) {
            return ritem.v;
        } else {
            let res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "rptunititem",
                    rptunitid: rptunitid
                }
            });
            this.rmrptunititem.push({
                k: rptunitid,
                v: res
            });
            return res;
        }
    },
    async getitem(isall) {
        if (isall == "1") {
            let r = await this.getallrptitem();
            return r;
        } else {
            let r = await this.getrmrptitem();
            return r;
        }
    },
    //仪器通道号
    rmInstrItem: '',
    async getallinstrItem() {
        if (this.rmInstrItem && this.rmInstrItem != "") {
            return this.rmInstrItem;
        } else {
            const res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "instrItem"
                }
            });
            this.rmInstrItem = res;
            try {
                let cData = this.rmInstrItem.filter(item => item.rpt_itemcode == "rmylcs");
            } catch (e) {
                console.log('dlldataerror 4');
                this.rmInstrItem = '';
            }
        }
        return this.rmInstrItem;
    },
    //所有报告项目
    rmallrptitem: '',
    async getallrptitem() {
        if (this.rmallrptitem && this.rmallrptitem != "") {
            return this.rmallrptitem;
        } else {
            const res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "rptallitem"
                }
            });
            this.rmallrptitem = res;
            try {
                let cData = this.rmallrptitem.filter(item => item.rpt_itemcode == "rmylcs");
            } catch (e) {
                console.log('dlldataerror 4');
                this.rmallrptitem = '';
            }
        }
        return this.rmallrptitem;
    },

    //所有抗生素字典
    rmalllabmed: '',
    async getalllabmed() {
        if (this.rmalllabmed && this.rmalllabmed != "") {
            return this.rmalllabmed;
        } else {
            const res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "labmed"
                }
            });
            this.rmalllabmed = res.Data;
            try {
                let cData = this.rmalllabmed.filter(item => item.medcode == "rmylcs");
            } catch (e) {
                console.log('dlldataerror med');
                this.rmalllabmed = '';
            }
        }
        return this.rmalllabmed;
    },

    //所有输入模板对应项目
    rminputmdlrptitem: '',
    async getinputmdlrptitem() {
        if (this.rminputmdlrptitem && this.rminputmdlrptitem != "") {
            return this.rminputmdlrptitem;
        } else {
            const res = await tool.request({
                url: "ucent/ddl",
                method: "post",
                data: {
                    action: "inputmdlitem"
                }
            });
            this.rminputmdlrptitem = res;
            try {
                let cData = this.rminputmdlrptitem.filter(item => item.rpt_itemcode == "rmylcs");
            } catch (e) {
                console.log('dlldataerror 4');
                this.rminputmdlrptitem = '';
            }
        }
        return this.rminputmdlrptitem;
    },
    localrmcomddl: [],
    getlocalrmcomddlkey() {

    },

    // 1= sql server 2=mysql 3=oracle
    _dbtype: "",
    get DbType() {
        if (this._dbtype && this._dbtype != "") {
            return this._dbtype;
        }
        $.ajax({
            async: false,
            url: tool.baseUrl + 'ucent/login',
            type: 'POST',
            data: {
                action: "dbtype"
            },
            dataType: 'json',
            success: function(data) {
                this._dbtype = data;
            }
        });
        return this._dbtype;
    },
    // DbType:  async function(){
    //     if (this._dbtype && this._dbtype != "") {
    //         return this._dbtype;
    //     } 
    //     else{
    //         let res = await tool.request({
    //             url: "ucent/login",
    //             method: "post",
    //             data: {
    //                 action: "dbtype"
    //             }
    //         });
    //         this._dbtype = res;
    //     }
    //     return this._dbtype;
    // },


    //是否是区域LIS模式
    IsAreaMode: false,
    IsAreaModeFun() {
        let _this = this;
        return new Promise((s, f) => {
            tool.request({
                    url: "ucent/login",
                    method: "post",
                    data: {
                        action: "IsAreaModeFun"
                    }
                })
                .then(res => {
                    _this.IsAreaMode = res;
                    s(_this.IsAreaMode);
                })
                .catch(e => {
                    _this.IsAreaMode = '';
                    f();
                });
        });
    },
    //申请单计价失败提醒消息时间参数
    msgparm: {
        localReqChargedt: ""
    }
};